﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

namespace T2task1
{
    class Program
    {
        static void Main(string[] args)
        {
            string connString = "sever=.;database=DB;Integrated Security=true";
            SqlConnection conn = new SqlConnection(connString);
            conn.Open();
            if (conn.State == ConnectionState.Open)
            {
                string sql = "select ID,Name,Price,Stock,Price*Stock as Total from Game";
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader rea = cmd.ExecuteReader();
                Console.WriteLine("序号\t游戏名称\t游戏价格\t库存数量\t小计");
                Console.WriteLine("+--------------------------------------------------------+");
                while (rea.Read())
                {
                    Console.WriteLine("{0}\t{1}\t{2}元\t\t{3:C}\t{4:C}元",rea["ID"], rea["Name"], rea["Price"], rea["Stock"], rea["Total"]);
                }
                rea.Close();
                Console.WriteLine("+--------------------------------------------------------+");
                string totalSql = "select sum(Price*Stock) from Game";
                cmd = new SqlCommand(totalSql, conn);
                string sum = string.Format("{0:C}", cmd.ExecuteReader());
                Console.WriteLine("游戏总金额：{0}元",sum);
            }
            conn.Close();
        }
    }
}
